<template>
  <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="50%" @ok="handleSubmit" destroyOnClose>
    <BasicForm @register="registerForm" >
      <template #reportConent="{ model, field }">
        <a-table :columns="columns" :data-source="content" bordered size="small"></a-table>
      </template>
    </BasicForm>
  </BasicDrawer>
</template>
<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
import { BasicForm, useForm } from '@apps/antd-admin/src/components/Form/index';
import { BasicDrawer, useDrawerInner } from '@apps/antd-admin/src/components/drawer';
import { formSchema } from '../data/data';
import { Api } from '../data/api';
// 声明Emits
const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const content = ref([]);

const [registerForm, { resetFields, setFieldsValue, saveOrUpdate, validate }] = useForm({
  rowKey: 'lostId',
  saveApi: Api.add,
  params:{
    feedState:1
  },
  disabled:true,
  updateApi: Api.update,
  schemas: formSchema,
  labelWidth: 120,
});
const columns = [
  {
    title: '客观性信息验证',
    dataIndex: 'label',
  },
  {
    title: '是否验证',
    dataIndex: 'valid',
  },
  {
    title: '验证结果',
    dataIndex: 'value',
  },
];
const [registerDrawer, { setDrawerProps, changeLoading, closeDrawer }] = useDrawerInner(async (data) => {
  await resetFields();
  changeLoading(false);
  isUpdate.value = !!data?.isUpdate;
  if (unref(isUpdate)) {
    content.value= JSON.parse(data.record.reportConent)
    await setFieldsValue({
      ...data.record,
    });
  }
});

const getTitle = computed(() => (!unref(isUpdate) ? '' : '查看报告'));

async function handleSubmit() {
  try {
    changeLoading(true);
    await saveOrUpdate(emit);
    closeDrawer();
  } finally {
    changeLoading(false);
  }
}
</script>
